package com.firewolf.springboot.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.firewolf.springboot.dao.DepartmentRepository;
import com.firewolf.springboot.entities.Department;

@Service
public class DepartmentService {
	
	@Autowired
	private DepartmentRepository deptDao;
	
	public void addData(List<Department> dList){
		deptDao.save(dList);
	}
	
	@Cacheable(value="depts",key="#id")
	public Department findById(Integer id){
		System.out.println("从数据库查询数据");
		return deptDao.findOne(id);
	}
	
	@CacheEvict(value="depts",key="#id")
	public void remove(Integer id){
		System.out.println("移除缓存,id:"+id);
	}
	
	@CacheEvict(value="depts",allEntries=true)
	public void clearCache(){
		System.out.println("清空所有缓存！！！");
	}
}
